<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      @submit.native.prevent
    >
      <el-form-item label="编码" prop="proOrderId">
        <el-input
          v-model="queryParams.proOrderId"
          filterable
          placeholder="请输入编码"
          @keyup.enter.native="handleQuery"
        ></el-input>
      </el-form-item>
      <el-form-item label="客户" prop="clientId">
        <el-select
          v-model="queryParams.clientId"
          filterable
          placeholder="请选择客户"
          remote
          reserve-keyword
          :remote-method="getListClient"
        >
          <el-option
            v-for="item in clientList"
            :key="item.clientId"
            :label="item.clientName"
            :value="item.clientId"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="下单时间" prop="createDate">
        <el-date-picker
          clearable
          v-model="queryParams.createDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择下单时间"
        >
        </el-date-picker>
      </el-form-item> -->

      <el-form-item label="下单时间" prop="createDate">
        <el-date-picker
          align="center"
          style="width: 240px"
          v-model="queryParams.createDateObj"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
<el-form-item label="审单时间" prop="createDate">
        <el-date-picker
          align="center"
          style="width: 240px"
          v-model="queryParams.createDateObj"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="交单时间" prop="submitTime">
        <el-date-picker
          clearable
          v-model="queryParams.submitTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择交单时间"
        >
        </el-date-picker>
      </el-form-item> -->

      <el-form-item label="交单时间" prop="submitTime">
        <el-date-picker
          align="center"
          style="width: 240px"
          v-model="queryParams.submitTimeObj"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item label="状态" prop="state">
        <el-select
          v-model="queryParams.state"
          placeholder="请选择状态"
          style="width: 100%"
        >
          <el-option
            v-for="item in dict.type.pro_order_state"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
			<el-form-item label="品牌" prop="brandId">
			  <el-select
			    style="width: 100%"
			    v-model="queryParams.brandId"
			    filterable
			    placeholder="请选择品牌"
			  >
			    <el-option
			      v-for="item in brandList"
			      :key="item.brandId"
			      :label="item.brandName"
			      :value="item.brandId"
			    >
			    </el-option>
			  </el-select>
			</el-form-item>
			<el-form-item label="变更单审核" prop="changeReview">
			  <el-select
			    style="width: 100%"
			    v-model="queryParams.changeReview"
			    filterable
			    placeholder="请选择"
			  >
			    <el-option
			      key="2"
			      label="待审核"
			      value="2"
			    />
			    <el-option
			      key="1"
			      label="已审核"
			      value="1"
			    />
			  </el-select>
			</el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['md:order:add']"
          >新增</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="!!multiple"
          @click="handleDelete"
          v-hasPermi="['md:order:remove']"
          >删除</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['md:order:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="orderList"
      @selection-change="handleSelectionChange"
      :row-class-name="tableRowClassName"
      :max-height="maxHeight"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="订单编号"
        align="center"
        prop="proOrderId"
        width="100"
      >
        <template slot-scope="{ row }">
          <el-link
            v-if="row.state !== '4'"
            type="primary"
            @click="handleRoom(row)"
            >{{ row.proOrderId }}</el-link
          >
          <template v-else>{{ row.proOrderId }}</template>
        </template>
      </el-table-column>
     <!-- <el-table-column
        label="客户名称"
        align="center"
        prop="clientName"
        min-width="160"
      /> -->
			<el-table-column
			  label="客户简称"
			  align="center"
			  prop="clientNick"
			  min-width="160"
			/>
      <el-table-column
        label="品牌"
        align="center"
        prop="brandName"
        min-width="100"
      />
      <el-table-column label="制单人" align="center" prop="preparedByName" />
      <el-table-column
        label="下单时间"
        align="center"
        prop="createDate"
        width="130"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
	  <el-table-column
	    label="审单时间"
	    align="center"
	    prop="createDate"
	    width="130"
	  >
	    <template slot-scope="scope">
	      <span>{{ parseTime(scope.row.createDate, "{y}-{m}-{d}") }}</span>
	    </template>
	  </el-table-column>
      <el-table-column
        label="交单时间"
        align="center"
        prop="submitTime"
        width="130"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.submitTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="地址"
        align="center"
        prop="address"
        min-width="250"
      />
      <el-table-column label="状态" align="center" prop="state">
        <template slot-scope="{ row }">
          <el-link
            type="primary"
            @click="
              () => {
                advanceLog = {
                  show: true,
                  data: {
                    ...row,
                  },
                };
              }
            "
            >{{ getTypeName(dict.type.pro_order_state, row.state) }}</el-link
          >
        </template>
      </el-table-column>
      <!-- <el-table-column label="商品价格" align="center" prop="commodityPrice" />
      <el-table-column label="邮费" align="center" prop="postage" />
      <el-table-column label="变更费" align="center" prop="changeFee" />
      <el-table-column
        label="总价调整"
        align="center"
        prop="totalPriceAdjustment"
      /> -->
	  <el-table-column label="类型" align="center" prop="closeStatus" />
      <el-table-column label="总价" align="center" prop="totalPrice" />
	  <el-table-column label="返利金" align="center" prop="isUsingRebate" >
		  <template slot-scope="scope">
		    <span v-if="scope.row.isUsingRebate==1">是</span>
			<span v-else>否</span>
			</template>
	  </el-table-column>
	  <el-table-column label="变更单" align="center" prop="changeReview" >
	  		  <template slot-scope="scope">
	  		    <span v-if="scope.row.changeReview==1">已审核</span>
				<span v-else-if="scope.row.changeReview==2">待财务审核</span>
	  			<span v-else>无</span>
	  			</template>
	  </el-table-column>
      <el-table-column
        label="备注"
        align="center"
        prop="remark"
        min-width="150"
        show-overflow-tooltip
      />

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        min-width="300"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            :disabled="scope.row.state === '4'"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['md:order:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            :disabled="scope.row.state === '4'"
            @click="handleAdvance(scope.row)"
            v-hasPermi="['md:order:edit']"
            >推进</el-button
          >
		  <el-button
		    v-if="scope.row.closeStatus==0"
		    size="mini"
		    type="text"
		    icon="el-icon-edit"
		    @click="stopproduct(scope.row)"
		    v-hasPermi="['md:order:edit']"
		    >暂停</el-button
		  >
		  <el-button
		  v-if="scope.row.closeStatus==3 || scope.row.closeStatus==1"
		    size="mini"
		    type="text"
		    icon="el-icon-edit"
		    @click="recoverOrder(scope.row)"
		    v-hasPermi="['md:order:edit']"
		    >恢复</el-button
		  >
		  <el-button
		  v-if="scope.row.closeStatus==3"
		    size="mini"
		    type="text"
		    icon="el-icon-edit"
		    @click="closeproduct(scope.row)"
		    v-hasPermi="['md:order:edit']"
		    >关闭</el-button
		  >
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handlePrint(scope.row)"
            v-hasPermi="['md:order:edit']"
            >打印</el-button
          > -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            :disabled="scope.row.state === '4'"
            @click="handleRoom(scope.row)"
            v-hasPermi="['md:order:edit']"
            >绑定房间</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleSplit(scope.row)"
            >返单</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleCopy(scope.row)"
            >复制</el-button
          >
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            :disabled="scope.row.state === '4'"
            @click="handleDelete(scope.row)"
            v-hasPermi="['md:order:remove']"
            >删除</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单对话框 -->
    <el-dialog
      :close-on-click-modal="false"
      :title="title"
      :visible.sync="open"
      width="700px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="客户" prop="clientId">
              <el-select
                style="width: 100%"
                v-model="form.clientId"
                filterable
                placeholder="请选择客户"
                remote
                reserve-keyword
                :remote-method="getListClient"
                @change="handleClientChange"
              >
                <el-option
                  v-for="item in clientList"
                  :key="item.clientId"
                  :label="item.clientName"
                  :value="item.clientId"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="tel">
              <el-input v-model="form.tel" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="下单时间" prop="createDate">
              <el-date-picker
                style="width: 100%"
                clearable
                v-model="form.createDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择下单时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="交单时间" prop="submitTime">
              <el-date-picker
                style="width: 100%"
                clearable
                v-model="form.submitTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择交单时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="地址" prop="address">
              <el-input v-model="form.address" placeholder="请输入地址" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态" prop="state">
              <el-select
                v-model="form.state"
                placeholder="请选择状态"
                style="width: 100%"
                :disabled="!!form.proOrderId"
              >
                <el-option
                  v-for="item in dict.type.pro_order_state"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="状态" prop="otherState">
              <el-checkbox-group v-model="form.otherState">
                <el-checkbox label="0">加急</el-checkbox>
                <el-checkbox label="1">水洗</el-checkbox>
                <el-checkbox label="2">正常</el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="品牌" prop="brandId">
              <el-select
                style="width: 100%"
                v-model="form.brandId"
                filterable
                placeholder="请选择品牌"
              >
                <el-option
                  v-for="item in brandList"
                  :key="item.brandId"
                  :label="item.brandName"
                  :value="item.brandId"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="扣费方式" prop="isUsingRebate">
              <el-checkbox-group v-model="form.isUsingRebate">
                <el-checkbox label="1">优先使用返利金账户</el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="打印LOGO" prop="isprintlogo">
              <el-checkbox-group v-model="form.isprintlogo">
                <el-checkbox label="1">是</el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input
                v-model="form.remark"
                placeholder="请输入备注"
                type="textarea"
                :rows="3"
              />
            </el-form-item>
          </el-col>
        </el-row>
				<el-row>
				  <el-col :span="24">
				    <el-form-item label="财务备注" prop="financialRemark">
				      <el-input
				        v-model="form.financialRemark"
				        placeholder="请输入财务备注"
				        type="textarea"
				        :rows="3"
				      />
				    </el-form-item>
				  </el-col>
				</el-row>
				<!-- <el-row>
				<el-col :span="24">
				<el-form-item label="免除金额" prop="amountWaived">
				  <el-input v-model="form.amountWaived" placeholder="0.00" />
				</el-form-item>
				</el-col>
				</el-row> -->
				
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 绑定房间弹窗 -->
    <room-view
      v-if="room.show"
      :show.sync="room.show"
      v-bind="room"
      @update="getList()"
      @on-split="handleSplit"
      @on-copy-change="handleCopyChange"
    ></room-view>
    <!-- 拆单 -->
    <split-view
      v-if="split.show"
      :show.sync="split.show"
      v-bind="split"
    ></split-view>

    <!-- 推进 -->
    <advance-view
      v-if="advance.show"
      :show.sync="advance.show"
      v-bind="advance"
      @update="getList()"
    ></advance-view>

    <!-- 打印 -->
    <print-view
      v-if="print.show"
      :show.sync="print.show"
      v-bind="print"
    ></print-view>

    <!-- 推进记录 -->
    <log-view
      v-if="advanceLog.show"
      :show.sync="advanceLog.show"
      v-bind="advanceLog"
    ></log-view>
	
    <!-- 复制订单 -->
    <copy-client-view
      v-if="copy.show"
      :show.sync="copy.show"
      v-bind="copy"
      @on-change="handleCopyChange"
    ></copy-client-view>
  </div>
</template>

<script>
import {
  listOrder,
  getOrder,
  delOrder,
  addOrder,
  updateOrder,
  stopproduct,
  recoverOrder,
  closeOrder,
  closeproduct,
  updatemoneyProOrder,
} from "@/api/asc/order";
import { listClient, getClient } from "@/api/mes/md/client";
import { listBrand } from "@/api/money/brand";
import RoomView from "./mods/room";
import SplitView from "./split";
import AdvanceView from "./advance";
import PrintView from "./print";
import LogView from "./advance/log";
import CopyClientView from "./copyClient";
import commonMix from "@/utils/mixins/common";

export default {
  name: "Order",
  dicts: ["pro_order_state"],
  mixins: [commonMix],
  components: {
    RoomView,
    SplitView,
    AdvanceView,
    PrintView,
    LogView,
    CopyClientView,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      orderList: [],
      clientList: [],
	  isUsingRebate:false,
	  isprintlogo:false,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
	  opens: false,
	  lfmoney:0.00,
	  orderid:"",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        orderId: null,
        clientId: null,
        state: null,
        createDate: null,
        submitTime: null,
        createDateObj: null,
        submitTimeObj: null,
      },
      // 表单参数
      form: {
		  'brandId':1,
	  },
      // 表单校验
      rules: {
        clientId: [
          { required: true, message: "请选择客户", trigger: "change" },
        ],
        createDate: [
          { required: true, message: "请选择下单时间", trigger: "change" },
        ],
        submitTime: [
          { required: true, message: "请选择交单时间", trigger: "change" },
        ],
        state: [{ required: true, message: "请选择状态", trigger: "change" }],
        otherState: [
          { required: true, message: "请选择状态", trigger: "change" },
        ],
		brandId: [
		  { required: true, message: "请选择品牌", trigger: "change" },
		],
      },
      room: {
        show: false,
        data: null,
      },
      split: {
        show: false,
        data: null,
      },
      advance: {
        show: false,
        data: null,
      },
      print: {
        show: false,
        data: null,
      },
      advanceLog: {
        show: false,
        data: null,
      },
      copy: {
        show: false,
        data: null,
      },
      brandList: [
	  ],
    };
  },
  created() {
    this.getList();
    this.getListClient();
    this.getBrandList();
  },
  methods: {
    tableRowClassName({ row }) {
      if (row.otherState?.includes("0")) {
        return "success-row";
      } else if (row.otherState?.includes("1")) {
        return "warning-row";
      }
      return "";
    },
	
    getListClient(clientName = "") {
      listClient({
        pageNum: 1,
        pageSize: 100,
		enableFlag:'Y',
        clientName,
        id: "1107",
      }).then(({ rows }) => {
        this.clientList = rows;
      });
    },

    getBrandList() {
      listBrand({
        pageNum: 1,
        pageSize: 500,
      }).then(({ rows }) => {
        this.brandList = rows;
      });
    },

    remoteMethod(query) {
      this.getListClient(query);
      console.log(query);
      // if (query !== '') {
      //   this.loading = true;
      //   setTimeout(() => {
      //     this.loading = false;
      //     this.options = this.list.filter(item => {
      //       return item.label.toLowerCase()
      //         .indexOf(query.toLowerCase()) > -1;
      //     });
      //   }, 200);
      // } else {
      //   this.options = [];
      // }
    },

    /** 查询订单列表 */
    getList() {
      this.loading = true;
      const params = {
        ...this.queryParams,
        createDateStart: this.queryParams.createDateObj?.[0] || null,
        createDateEnd: this.queryParams.createDateObj?.[1] || null,
        submitTimeStart: this.queryParams.submitTimeObj?.[0] || null,
        submitTimeEnd: this.queryParams.submitTimeObj?.[1] || null,
      };
      delete params.createDateObj;
      delete params.submitTimeObj;
      listOrder(params).then((response) => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleClientChange() {
      const { province, city, district, address, tel } = this.clientList?.find(
        (e) => e.clientId === this.form.clientId
      );
      this.form.address = `${province || ""}${city || ""}${district || ""}${
        address || ""
      }`;
      this.form.tel = tel;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
	cancels() {
	  this.opens = false;
	  this.lfmoney=0.00;
	  this.reset();
	},
    // 表单重置
    reset() {
      this.form = {
        otherState: ["2"],
		isUsingRebate:[],
		isprintlogo:[],
		brandId:1,
        tel: null,
        proOrderId: null,
        clientId: null,
        clientName: null,
        preparedBy: null,
        preparedByName: null,
        createDate: this.parseTime(new Date(), "{y}-{m}-{d}"),
        submitTime: this.parseTime(
          new Date().valueOf() + 24 * 3600 * 10000,
          "{y}-{m}-{d}"
        ),
        remark: null,
        address: null,
        state: "0",
        commodityPrice: null,
        postage: null,
        changeFee: null,
        totalPriceAdjustment: null,
        totalPrice: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.createDateObj = null;
      this.queryParams.submitTimeObj = null;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.proOrderId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单";
    },
    // 获取数据
    async getOrderData(proOrderId) {
      const { data } = await getOrder(proOrderId);
      return data;
    },
    /** 修改按钮操作 */
    async handleUpdate(row) {
      this.reset();
      const proOrderId = row.proOrderId || this.ids;
      const data = await this.getOrderData(proOrderId);
      this.form = {
        ...data,
        otherState: data?.otherState ? data.otherState?.split(",") : [],
		isUsingRebate: data?.isUsingRebate ? data.isUsingRebate?.split(",") : [],
      };

      this.open = true;
      this.title = "修改订单";
      this.getListClient(row.clientName);
    },

    // 打印
    handlePrint(row) {
      this.print = {
        show: true,
        data: {
          ...row,
        },
      };
    },

    // 推进
    handleAdvance(row) {
      this.advance = {
        show: true,
        data: {
          ...row,
        },
      };
    },
	//暂停生产
	stopproduct(row){
		const proOrderIds = row.proOrderId || this.ids;
		stopproduct(proOrderIds).then(({ data }) => {
		  this.$modal.msgSuccess("暂停成功");
		  this.open = false;
		  this.getList();
		});
		
	},
	//恢复
	recoverOrder(row){
		const proOrderIds = row.proOrderId || this.ids;
		recoverOrder(proOrderIds).then(({ data }) => {
		  this.$modal.msgSuccess("恢复成功");
		  this.open = false;
		  this.getList();
		});
	},
	//提交关闭
	closeproduct(row){
		const proOrderIds = row.proOrderId || this.ids;
		closeproduct(proOrderIds).then(({ data }) => {
		  this.$modal.msgSuccess("提交关闭");
		  this.open = false;
		  this.getList();
		});
	},
	

    /** 绑定房间 */
    handleRoom(row) {
      this.room = {
        show: true,
        data: {
          ...row,
        },
      };
    },
    /** 拆单 */
    handleSplit(row) {
      this.split = {
        show: true,
        data: {
          ...row,
        },
      };
    },

    /** 提交按钮 */
    async submitForm() {
      await this.$refs["form"].validate();
      const { data } = await getClient(this.form?.clientId);

      const query = {
        ...this.form,
        clientName: data.clientName,
        otherState: this.form.otherState?.join(),
		isUsingRebate: this.form.isUsingRebate?.join(),
      };

      if (this.form.proOrderId != null) {
        updateOrder(query).then(({ data }) => {
          this.$modal.msgSuccess("修改成功");
          this.open = false;
          this.getList();
          this.goPages(data);
        });
      } else {
        addOrder(query).then(({ data }) => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
          this.goPages(data);
        });
      }
    },
    // 复制订单
    handleCopy(row) {
      this.copy = {
        show: true,
        data: row,
      };
    },
    handleCopyChange(data) {
      this.goPages(data);
    },
    /** 跳转绑定房间 */
    async goPages(id) {
      const data = await this.getOrderData(id);
      this.handleRoom(data);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const proOrderIds = row.proOrderId || this.ids;
      this.$modal
        .confirm('是否确认删除订单编号为"' + proOrderIds + '"的数据项？')
        .then(function () {
          return delOrder(proOrderIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "md/order/export",
        {
          ...this.queryParams,
		  createDateStart: this.queryParams.createDateObj?.[0] || null,
		  createDateEnd: this.queryParams.createDateObj?.[1] || null,
        },
        `order_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep {
  .el-form-item {
    input {
      text-align: left;
    }
  }
  .el-table .warning-row {
    background: #b3d8ff;
  }

  .el-table .success-row {
    background: #fbc4c4;
  }
}
</style>
